<?
$tmppath="../../";
REQUIRE ($tmppath."include/login.php");
REQUIRE ($tmppath."$templates/up.php");
REQUIRE($tmppath."include/connect.php");

$bat_id=$batiment;
//************************************************************
//***********Selection de bonus du batiments******************
//************************************************************

$query="SELECT batiment_bonus FROM SDBatiment  WHERE batiment_id=$batiment";
$resultat=mysql_query($query);
$tmp=mysql_fetch_row($resultat);

$t_bonus=0;
 IF (!empty($tmp[0])){
		  		$bonus_tmp=EXPLODE("/",$tmp[0]); 
				FOREACH($bonus_tmp as $var){
                    $bon_tmp=EXPLODE("*",$var);
                  
					$bon_num[$t_bonus]=$bon_tmp[0];


					$bonus2[$bon_tmp[0]]=$bon_tmp[1];
					$t_bonus++;
                }		  
		  }
//************************************************************
//***********Selection des sorts******************************
//************************************************************		  

$query="SELECT con_invention FROM SDconnP where con_id=1";
$resultat=mysql_query($query);
$tmp=mysql_fetch_row($resultat);
$inventiontmp=EXPLODE("/",$tmp[0]);


FOREACH($inventiontmp as $element){
    if ($drap==1){ $querytmp.=" OR ";}ELSE{$querytmp.=" WHERE ";}
    $i=$element;
    $invention[$i]=1;
    $querytmp.="invention_precedent=$i";
    $drap=1;
}    //Fin du foreach





$query="SELECT invention_id, invention_name,invention_prerequis FROM Usort $querytmp AND invention_categorie='magie'";
$resultat=mysql_query($query);
$tmp=mysql_fetch_row($resultat);


$total=0;

WHILE ($request=mysql_fetch_array($resultat)){

$idinvention=$request[0];
$prerequis=EXPLODE("/",$request[2]);
$binvention=0;

      if (!empty($prerequis[0])){
       FOREACH($prerequis as $element){
            IF ($invention[$element]!=1){
                $binvention=1;

            }
            
   }
            
       }//Fin du foreach


IF ($invention[$idinvention]==1){
	$total++;
    $inventionid[$total]=$request[0];
	$iname[$total]=$request[1];

	
}
       
}//Fin du while.


REQUIRE("tour_function.php");
$titre="Rechercher sort.";
titre($titre);

mysql_close;




?>

<title>Sombre destin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
@import url(../../templates/default/vrt-team.css);
</style>
</head>
<body bgcolor="#00CCFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!***********************************************************************
***********Les script javascript de la page***************************
***********************************************************************>

<script language="JavaScript" type="text/JavaScript">
<!--

tribulibre=<? echo $tribu_libre ?>;


image=new Array(<? echo $total ?>);
iname=new Array(<? echo $total ?>);
description=new Array(<? echo $total ?>);


<?
/*
echo"image[0]=\"vide.gif\";";
//Pour le chargement des images dans les variable javascript.
//***********************************************************
FOR ($i=1; $i< $total+1; $i++){
$bonnumero=$bnumero[$i];
echo"image[$bonnumero]=\"$bimage[$bonnumero]\";";
}*/
//Pour la chargement du temps de construction dans les variable javascript.
//*************************************************************************
echo"iname[0]=\"\";";
FOR ($i=1; $i< $total+1; $i++){
$bonnumero=$inventionid[$i];
echo"iname[$i]=\"$iname[$i]\";";
}
/*
//Pour la chargement de la description dans les variable javascript.
//******************************************************************
echo"description[0]=\"N/A\";";
FOR ($i=1; $i< $total+1; $i++){
$bonnumero=$bnumero[$i];
echo"description[$bonnumero]=\"$bdescription[$bonnumero]\";";
}*/

?>
function add(){
var tribul=document.form1.tribul.value;
var tribu=document.form1.tribu.value;
		
	if (tribul!=0){
		document.form1.tribu.value++;
		document.form1.tribul.value--;
	}

	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}


 
	
}

function sous(){
var tribul=document.form1.tribul.value;
var tribu=document.form1.tribu.value;
		
		if (document.form1.tribu.value!=0){
			document.form1.tribu.value--;
			document.form1.tribul.value++;
		}	

	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}

}

function onch(){
		document.form1.tribul.value= tribulibre-document.form1.tribu.value;
		if (document.form1.tribu.value<0){ document.form1.tribu.value=0; document.form1.tribul.value=tribulibre; }
		if (document.form1.tribu.value>tribulibre){ document.form1.tribu.value=tribulibre;document.form1.tribul.value=0; }

	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}
}

function onch2(){
		document.form1.tribul.value= tribulibre-document.form1.tribu.value;		

	if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}
}

function chgimg(){
		document.imgbatiment.src = "../../images/batiments/"+image[document.form1.batiment.value];
		chgtmp();
		
		if (document.form1.batiment.value!=0 && document.form1.tribu.value!=0){
			chgtour() 
		}
		
		document.form2.description.value=description[document.form1.batiment.value];
		

}	

function chgtmp(){
 document.form2.tmpc.value=tmpsconstr[document.form1.batiment.value];
}

function chgtour(){
 document.form2.tourc.value=Math.ceil(tmpsconstr[document.form1.batiment.value]/(10*document.form1.tribu.value));
}

//-->
</script>
<!/***********************************************************************
******************************Fin des javascripts***********************
***********************************************************************>
<div align="center">
<?
if (!empty($erreur)){
echo"<table width=\"85%\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\" background=\"../Templates/Default/Fond.jpg\"><tr><td><strong><font color=\"#FF0000\">$erreur</font></strong></td></table><BR>";

}


?>
  <table width="75%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><p align="center">&nbsp;</p>
        <form method="post" name="form1" action="../villes/ville_test.php" target="_self">
          <div align="center"></div>
          <table width="300" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#333333">
            <tr> 
              <td width="141"><div align="right">Apprentis libre :</div></td>
              <td width="153"> 
                <input name="tribul" type="text" id="tribul" value="<? echo $tribu_libre ?>" size="10" maxlength="5" onChange="onch2()"></td>
            </tr>
          </table>
          <p align="center">&nbsp;</p>
          <p align="center"><strong>Construction :</strong></p>
          <table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="40%"><div align="center"><img src="../../images/vide.gif" name="imgbatiment" width="50" height="50" border="1" align="middle" id="imgbatiment"></div></td>
              <td width="60%"><div align="center"> 
                  <select name="batiment" size="1" id="batiment" onChange="chgimg()" >
                    <option value="0">Choisissez la construction</option>
                   <?
                   //On met les nom dans l'option.
                  //******************************
                  
				   FOR ($i=1; $i< $total+1; $i++){


                        $bonnumero=$inventionid[$i];
                        
						echo"<option value=\"$bonnumero\">$iname[$i]</option></br>";
				   
				   }
				  
                  ?>
				  </select>
                </div></td>
            </tr>
          </table>
          <br>
          <table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td><div align="right">Combien de magiciens?</div></td>
              <td><div align="center">
                  <input type="button" name="Submit22" value="-" onClick="sous()">
                  <input name="tribu" type="text" id="tribu" value="0" size="5" maxlength="3" onChange="onch()">
                  <input type="button" name="Submit2" value="+" onClick="add()">
                </div></td>
            </tr>
          </table>
          <p align="center"> 
	<?
	echo"<input name=\"ville\" type=\"hidden\" id=\"ville\" value=\"$ville\">";

 
	?>	  
            <input name="choix" type="hidden" id="choix" value="construire">
            <input type="submit" name="Submit" value="Envoyer" >
          </p>
          </form>
        <form name="form2" method="post" action="">
          <p>&nbsp;</p>
          <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
            <tr>
              <td><div align="center"> 
                  <p>Temps de construction :<br>
                    <input name="tmpc" type="text" id="tmpc3" value="0" size="10" maxlength="10">
                    <br>
                    Bonus :<br>
                    <input name="bonus" type="text" id="bonus" value="0" size="10" maxlength="0" readonly>
                    <br>
                    Tour pour la construction :<br>
                    <input name="tourc" type="text" id="tourc" value="0" size="10" maxlength="10">
                  </p>
                  </div></td>
              <td width="0" height="0"> <div align="center">Descrition:<br>
                  <textarea name="description" cols="50" rows="4" id="description"></textarea>
                </div></td>
            </tr>
          </table>
          <p>&nbsp; </p>
        </form>
        
      </td>
    </tr>
  </table>
  <p align="left">&nbsp;</p>
</div>
</body></html>
